package com.share.shareplatform.shareuser.service.impl;


import com.share.shareplatform.shareuser.dao.RoleDao;
import com.share.shareplatform.shareuser.dao.UserDao;
import com.share.shareplatform.pojo.Role;
import com.share.shareplatform.pojo.User;
import com.share.shareplatform.shareuser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleDao roleDao;

    //添加用户同时绑定身份
    @Override
    public Long addOne(User user) {
        Role role = roleDao.findOneByName("ROLE_user");
        user.setRoleId(role.getId());
        return userDao.addOne(user);
    }

    @Override
    public Integer updateOne(User user) {
        return userDao.updateOne(user);
    }

    //只能对名称电话等信息进行修改
    @Override
    public Integer updateBaseOne(User user) {
        return userDao.updateBaseOne(user);
    }

    @Override
    public Integer deleteOneById(Long id) {
        return userDao.deleteOneById(id);
    }

    @Override
    public Integer deleteAllByIds(Long[] ids) {
        return userDao.deleteAllByIds(ids);
    }

    @Override
    public User findOneByUsername(String username) {
        return userDao.findOneByUsername(username);
    }

    @Override
    public User findOneById(Long id) {
        return userDao.findOneById(id);
    }

    @Override
    public List<User> findPage(Integer pageIndex, Integer pageSize) {
        return userDao.findPage((pageIndex-1)*pageSize,pageSize);
    }

    @Override
    public User findUserByUsernameAndPassword(User user) {
        return userDao.findUserByUsernameAndPassword(user);
    }

    @Override
    public User findOneSafeById(Long id) {
        return userDao.findOneSafeById(id);
    }

    @Override
    public List<User> findAllSafeByIds(Long[] ids) {
        return userDao.findAllSafeByIds(ids);
    }

    @Override
    public Map<Long, User> findAllSafeByIdsAsMap(List<Long> list) {
        return userDao.findAllSafeByIdsAsMap(list);
    }


}
